package sopt.engSearch;

import java.sql.SQLException;
import java.util.ArrayList;

import com.ibatis.sqlmap.client.SqlMapClient;

import comm.util.SoptHashMap;
import comm.util.SqlMapLoader;

public class QueryDataProc {
	private SqlMapClient sqlMapper = SqlMapLoader.getInstance();
	
	public QueryDataProc() {
	}
	
	public void regQuery(String q,String country){
		if(q.length()>0){
			try {
				SoptHashMap hm = new SoptHashMap();
				hm.put("Q", q);
				hm.put("COUNTRY", country);
				
				sqlMapper.insert("query.regQuery", hm);
			} catch (SQLException e) {
				
			}
		}
		
	}
	
	public ArrayList getRecentQueryList(){
		ArrayList lt = null;
		
		try {
			lt = (ArrayList)sqlMapper.queryForList("query.getRecentQueryList");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			return lt;
		}
		
		return lt;
	}
	
	public ArrayList getMostQueryList(){
		ArrayList lt = null;
		
		try {
			lt = (ArrayList)sqlMapper.queryForList("query.getMostQueryList");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			return lt;
		}
		
		return lt;
	}
	
	public String getUserCountry(String ip){
		String result = "";
		
		try {
			Object obj = sqlMapper.queryForObject("query.getUserCountry",ip);
			if(obj!=null)
				result = obj.toString();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			return result;
		}
		
		return result; 
	}
	
	public ArrayList getKoreanQueryList(){
		ArrayList lt = null;
		
		try {
			lt = (ArrayList)sqlMapper.queryForList("query.getKoreanQueryList");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			return lt;
		}
		return lt;
	}
	
	public ArrayList getAbroadQueryList(){
		ArrayList lt = null;
		
		try {
			lt = (ArrayList)sqlMapper.queryForList("query.getAbroadQueryList");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			return lt;
		}
		return lt;
	}
	
}
